package com.health.platform.common.core.entity;

import com.health.platform.common.utils.ThreadLocalUtil;
import com.health.platform.common.utils.MyUtils;
import org.springframework.util.StringUtils;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.Calendar;


/**
 * 通用查询实体类
 *
 * @author shi_xy_sr@neusiri.com
 * @date 2021/3/2 18:33
 */
public class CommonQueryEntity {

    /**
     * 区划编号
     */
    private String sgbCode;
    /**
     * 区划名称
     */
    private String sgbName;
    /**
     * 机构等级
     */
    private String unitLevel;

    /**
     * 机构编号
     */
    private String unitCode;

    /**
     * 类型
     */
    private String targetType;
    /**
     * 类型2
     */
    private String targetType2;
    /**
     * 备用维度
     */
    private String spareCode;
    /**
     * 备用维度1
     */
    private String spareCode1;

    /**
     * 指标类型
     */
    private String[] targetTypeArr;
    /**
     * 是否计算页面选择时间的上一年同期
     * 默认是false 不计算
     */
    private boolean compare;
    /**
     * 日期参数
     * 1 今日
     * 2 上一日
     * 3 近一周
     * 4 近一月
     * 5 上月
     * 6 本月
     * 7 近一年
     * 8 上年
     * 9 本年
     */
    private Integer dateType;

    /**
     * 自定义开始日期
     */
    private String startDate;

    /**
     * 自定义结束日期
     */
    private String endDate;
    /**
     * 区域代码截取长 2位-省、4位-市、6位-区、8位-县
     */
    private Integer substrIndex;
    /**
     * 折线图选择的时间
     */
    private Integer lineType;
    /**
     * 时间格式化格式
     */
    private String dateFormat;
    /**
     * 表名
     */
    private String tablename;
    /**
     * 区域构建体
     */
    private StringBuilder paramAreaBuilder = new StringBuilder();
    /**
     * 机构构建体
     */
    private StringBuilder paramUnitBuilder = new StringBuilder();
    /**
     * 页面选择时间构建体
     */
    private StringBuilder paramDateBuilder = new StringBuilder();
    /**
     * 页面选择时间的上一年同期构建体
     * （单纯为获取同比）
     */
    private StringBuilder paramDateCompareBuilder = new StringBuilder();
    /**
     * 页面选择年份的最近五年
     * （单纯为图表按着年份分组展示）
     */
    private StringBuilder paramDateRecentYearBuilder = new StringBuilder();
    /**
     * 页面选择年份的最近五年 分组数组
     */
    private String[] recentYearArr;
    /**
     * 页面选择年份的最近五年 的去年同期
     * （单纯为图表按着年份分组展示）
     */
    private StringBuilder paramDateRecentYearCompareBuilder = new StringBuilder();
    /**
     * 页面选择年份的最近五年 的去年同期 分组数组
     */
    private String[] recentYearCompareArr;
    /**
     * 页面选择日期的最近七天
     * （单纯为图表按着近七天分组展示）
     */
    private StringBuilder paramDateRecentDayBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近七天 分组数组
     */
    private String[] recentDayArr;
    /**
     * 页面选择日期的最近七天 的去年同期
     * （单纯为图表按着近七天分组展示）
     */
    private StringBuilder paramDateRecentDayCompareBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近七天 的去年同期 分组数组
     */
    private String[] recentDayCompareArr;
    /**
     * 页面选择日期的最近12周
     * （单纯为图表按着近12周分组展示）
     */
    private StringBuilder paramDateRecentWeekBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近12周 分组数组
     */
    private String[] recentWeekArr;
    /**
     * 页面选择日期的最近12周 的去年同期
     * （单纯为图表按着近12周分组展示）
     */
    private StringBuilder paramDateRecentWeekCompareBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近12周 的去年同期 分组数组
     */
    private String[] recentWeekCompareArr;
    /**
     * 页面选择日期的最近12月
     * （单纯为图表按着近12月分组展示）
     */
    private StringBuilder paramDateRecentMonthBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近12月 分组数组
     */
    private String[] recentMonthArr;
    /**
     * 页面选择日期的最近12月 的去年同期
     * （单纯为图表按着近12月分组展示）
     */
    private StringBuilder paramDateRecentMonthCompareBuilder = new StringBuilder();
    /**
     * 页面选择日期的最近12月 的去年同期 分组数组
     */
    private String[] recentMonthCompareArr;

    /**
     * 区域SQl拼接条件
     */
    private String conditionAreaStr;
    /**
     * 机构SQl拼接条件
     */
    private String conditionUnitStr;
    /**
     * 页面选择时间SQl拼接条件
     */
    private String conditionDateStr;
    /**
     * 页面选择时间的上一年同期SQl拼接条件
     */
    private String conditionCompareDateStr;
    /**
     * 页面选择年份的最近五年
     * （单纯为图表按着年份分组展示）
     */
    private String conditionRecentYearDateStr;
    /**
     * 页面选择年份的最近五年 的去年同期
     * （单纯为图表按着年份分组展示）
     */
    private String conditionRecentYearCompareDateStr;
    /**
     * 页面选择年份的最近七天
     * （单纯为图表按最近七天分组展示）
     */
    private String conditionRecentDayDateStr;
    /**
     * 页面选择年份的最近七天 的去年同期
     * （单纯为图表按最近七天分组展示）
     */
    private String conditionRecentDayCompareDateStr;
    /**
     * 页面选择日期的最近12月
     * （单纯为图表按最近12月分组展示）
     */
    private String conditionRecentMonthDateStr;
    /**
     * 页面选择日期的最近12月 的去年同期
     * （单纯为图表按最近12月分组展示）
     */
    private String conditionRecentMonthCompareDateStr;
    /**
     * 页面选择日期的最近12周
     * （单纯为图表按最近12周分组展示）
     */
    private String conditionRecentWeekDateStr;
    /**
     * 页面选择日期的最近12周 的去年同期
     * （单纯为图表按最近12周分组展示）
     */
    private String conditionRecentWeekCompareDateStr;
    /**
     * 页面选择时间按周期分组后的SQl拼接条件
     */
    private String conditionRecentDateStr;
    /**
     * 页面选择时间按周期分组后的上一年同期SQl拼接条件
     */
    private String conditionRecentCompareDateStr;

    //***********************************************************以下属性为根据参数修改的方法*****************************************************

    // 区域
    public void setSgbCode(String sgbCode) {
        this.sgbCode = sgbCode;
        if (!StringUtils.hasText(this.sgbCode)) {
            // 如果前端页面没有给传递区划编号，那么就查询当前登录人所在区划下的所有区划
            sgbCode = ThreadLocalUtil.get().getBody().getAreainfo().getCode();
        }
        // 清空
        paramAreaBuilder.delete(0, paramAreaBuilder.length());
        paramAreaBuilder.append(" and t.GBCODE like '" + sgbCode + "%' ");
    }
    // 区域名称
    public void setSgbName(String sgbName) { this.sgbName = sgbName; }
    //备用维度
    public void setSpareCode(String spareCode) { this.spareCode = spareCode; }
    //备用维度1
    public void setSpareCode1(String spareCode1) { this.spareCode1 = spareCode1; }

    // 机构等级
    public void setUnitLevel(String unitLevel) {
        this.unitLevel = unitLevel;
        paramUnitBuilder.append(" and t1.unitLevel = " + unitLevel + " ");
    }

    // 机构编码
    public void setUnitCode(String unitCode) {
        this.unitCode = unitCode;
        paramUnitBuilder.append(" and t.ORG_CODE = " + unitCode + " ");
    }
    public void setStartDate(String startDate) {
        this.startDate = startDate;
        if(StringUtils.hasText(startDate)){
            DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate parse = LocalDate.parse(startDate, fmDate);
            //去年今天
            LocalDate dateLast = parse.minusYears(1);
            String dateLastStr = dateLast.format(fmDate);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd') >='" + startDate + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')>='" + dateLastStr + "'");
        }
    }
    public void setEndDate(String endDate) {
        this.endDate = endDate;
        if (StringUtils.hasText(endDate)) {
            DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate parse = LocalDate.parse(endDate, fmDate);
            //去年今天
            LocalDate dateLast = parse.minusYears(1);
            String dateLastStr = dateLast.format(fmDate);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd') <='" + endDate + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')<='" + dateLastStr + "'");
            //获取最近五年和同比
            this.getYearCompare(endDate);
            //获取最近12月和同比
            this.getMonthCompare(endDate);
            //获取最近12周和同比
            this.getWeekCompare(endDate);
            //获取最近7天和同比
            this.getDayCompare(endDate);
        }
    }
    /**
     * 设置日期参数
     * 1 今日
     * 2 上一日
     * 3 近一周
     * 4 近一月
     * 5 上月
     * 6 本月
     * 7 近一年
     * 8 上年
     * 9 本年
     * 其他值 则为页面自定义选择的时间
     */
    public void setDateType(Integer dateType) {
        this.dateType = dateType;
        String dateStr = null;
        String dateLastStr = null;
        String keydateLastStr = null;
        if(dateType == null ){
            return;
        }
        // 月格式化
        DateTimeFormatter monthDate = DateTimeFormatter.ofPattern("yyyy-MM");
        DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if (1 == dateType) {
            //当天
            dateStr = LocalDate.now().format(fmDate);
            //去年的当天
            dateLastStr = LocalDate.now().plus(-1, ChronoUnit.YEARS).format(fmDate);
            // 时间条件
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')='" + dateStr + "'");
            //同比时间条件
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')='" + dateLastStr + "'");
            keydateLastStr = dateStr;
        } else if (2 == dateType) {
            // 上一日
            dateStr = LocalDate.now().minus(1, ChronoUnit.DAYS).format(fmDate);
            //去年的上一日
            dateLastStr = LocalDate.now().minus(1, ChronoUnit.DAYS).plus(-1, ChronoUnit.YEARS).format(fmDate);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')='" + dateStr + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd')='" + dateLastStr + "'");
            keydateLastStr = dateStr;
        } else if (3 == dateType){
            //近一周
        } else if (4 == dateType){
            //近一月
        }  else if (5 == dateType) {
            // 上月今天
            dateStr = LocalDate.now().minusMonths(1).format(monthDate);
            // 去年同期
            dateLastStr = LocalDate.now().minusMonths(1).plus(-1, ChronoUnit.YEARS).format(monthDate);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM')='" + dateStr + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM')='" + dateLastStr + "'");
            keydateLastStr = LocalDate.now().minusMonths(1).format(fmDate);
        } else if (6 == dateType) {
            // 本月
            dateStr = LocalDate.now().minusMonths(0).format(monthDate);
            //去年的当天
            dateLastStr = LocalDate.now().minusMonths(0).plus(-1, ChronoUnit.YEARS).format(monthDate);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy-MM')='" + dateStr + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM')='" + dateLastStr + "'");
            keydateLastStr = LocalDate.now().format(fmDate);
        } else if (7 == dateType){
            //近一年
        } else if (8 == dateType) {
            //  上年
            dateStr = String.valueOf(LocalDate.now().getYear() -1);
            // 去年同期
            dateLastStr = String.valueOf(LocalDate.now().getYear() - 2);
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy')='" + dateStr + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy')='" + dateLastStr + "'");
            keydateLastStr = LocalDate.now().minusYears(1).format(fmDate);
        } else if (9 == dateType) {
            //   本年
            dateStr = String.valueOf(LocalDate.now().getYear() );
            //去年的当天
            dateLastStr = String.valueOf(LocalDate.now().getYear() - 1);
            //这块有个逻辑，公卫服务最近五年，要判断当前月份是否在6.1号以后，若在6.1号以前，最近五年不包括当前年，若在6.1号以后包含6.1，最近五年包含当前年
           /* Calendar calendar = Calendar.getInstance();
            int month = calendar.get(Calendar.MONTH) + 1;
            String topYear = dateStr;
            if (month < 6){
                topYear = Integer.parseInt(dateStr) -1 + "";
            }*/
            paramDateBuilder.append("and to_char(t.bus_date, 'yyyy')='" + dateStr + "'");
            paramDateCompareBuilder.append("and to_char(t.bus_date, 'yyyy')='" + dateLastStr + "'");
            keydateLastStr = LocalDate.now().format(fmDate);
        }
        //获取最近五年和同比
        this.getYearCompare(keydateLastStr);
        //获取最近12月和同比
        this.getMonthCompare(keydateLastStr);
        //获取最近12周和同比
        this.getWeekCompare(keydateLastStr);
        //获取最近7天和同比
        this.getDayCompare(keydateLastStr);
    }
    /**
     * 获得传入时间的最近五年
     */
    private void getYearCompare(String dateStr) {
        DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate parseDate = LocalDate.parse(dateStr, fmDate);
        //当前年
        String chooseYear = parseDate.getYear() + "";
        paramDateRecentYearBuilder.append("and to_char(t.bus_date, 'yyyy') in (" + MyUtils.getRecentYear(chooseYear) + ")");
        recentYearArr = MyUtils.getRecentYearArr(chooseYear);
        //上一年
        LocalDate parseLastDate = parseDate.minusYears(1);
        String chooseLastYear = parseLastDate.getYear() + "";
        paramDateRecentYearCompareBuilder.append("and to_char(t.bus_date, 'yyyy') in (" + MyUtils.getRecentYear(chooseLastYear) + ")");
        recentYearCompareArr = MyUtils.getRecentYearArr(chooseLastYear);
    }
    /**
     * 获得传入时间的最近12月
     */
    private void getMonthCompare(String dateStr) {
        DateTimeFormatter monthDate = DateTimeFormatter.ofPattern("yyyy-MM");
        DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate parseDate = LocalDate.parse(dateStr, fmDate);
        String dateStr0 = parseDate.format(monthDate);
        String dateStr1 = parseDate.minusMonths(1).format(monthDate);
        String dateStr2 = parseDate.minusMonths(2).format(monthDate);
        String dateStr3 = parseDate.minusMonths(3).format(monthDate);
        String dateStr4 = parseDate.minusMonths(4).format(monthDate);
        String dateStr5 = parseDate.minusMonths(5).format(monthDate);
        String dateStr6 = parseDate.minusMonths(6).format(monthDate);
        String dateStr7 = parseDate.minusMonths(7).format(monthDate);
        String dateStr8 = parseDate.minusMonths(8).format(monthDate);
        String dateStr9 = parseDate.minusMonths(9).format(monthDate);
        String dateStr10 = parseDate.minusMonths(10).format(monthDate);
        String dateStr11 = parseDate.minusMonths(11).format(monthDate);
        paramDateRecentMonthBuilder.append("and to_char(t.bus_date, 'yyyy-MM') in ('"+dateStr0+"','"+dateStr1+"','"+dateStr2+"','"+dateStr3+"','"+dateStr4+"','"+dateStr5+"','"+dateStr6+"','"+dateStr7+"','"+dateStr8+"','"+dateStr9+"','"+dateStr10+"','"+dateStr11+"')");
        recentMonthArr = new String[]{dateStr11,dateStr10,dateStr9,dateStr8,dateStr7,dateStr6,dateStr5,dateStr4,dateStr3,dateStr2,dateStr1,dateStr0};
        //上一年
        LocalDate parseLastDate = parseDate.minusYears(1);
        String dateLastStr0 = parseLastDate.format(monthDate);
        String dateLastStr1 = parseLastDate.minusMonths(1).format(monthDate);
        String dateLastStr2 = parseLastDate.minusMonths(2).format(monthDate);
        String dateLastStr3 = parseLastDate.minusMonths(3).format(monthDate);
        String dateLastStr4 = parseLastDate.minusMonths(4).format(monthDate);
        String dateLastStr5 = parseLastDate.minusMonths(5).format(monthDate);
        String dateLastStr6 = parseLastDate.minusMonths(6).format(monthDate);
        String dateLastStr7 = parseLastDate.minusMonths(7).format(monthDate);
        String dateLastStr8 = parseLastDate.minusMonths(8).format(monthDate);
        String dateLastStr9 = parseLastDate.minusMonths(9).format(monthDate);
        String dateLastStr10 = parseLastDate.minusMonths(10).format(monthDate);
        String dateLastStr11 = parseLastDate.minusMonths(11).format(monthDate);
        paramDateRecentMonthCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM') in ('"+dateLastStr0+"','"+dateLastStr1+"','"+dateLastStr2+"','"+dateLastStr3+"','"+dateLastStr4+"','"+dateLastStr5+"','"+dateLastStr6+"','"+dateLastStr7+"','"+dateLastStr8+"','"+dateLastStr9+"','"+dateLastStr10+"','"+dateLastStr11+"')");
        recentMonthCompareArr = new String[]{dateLastStr11,dateLastStr10,dateLastStr9,dateLastStr8,dateLastStr7,dateLastStr6,dateLastStr5,dateLastStr4,dateLastStr3,dateLastStr2,dateLastStr1,dateLastStr0};
    }
    /**
     * 获得传入时间的最近12周
     */
    private void getWeekCompare(String dateStr) {
        DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate parseDate = LocalDate.parse(dateStr, fmDate);
        String nowYear = String.valueOf(parseDate.getYear());
        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,4);
        //获取当前时间在当前年的第几周
        int week= parseDate.get(weekFields.weekOfWeekBasedYear());
        //    获取近12周 如果小于12 那么有几周算几周
        String dateStr1 = week >= 10 ? ""+week : "0"+week;
        String dateStr2 = (week-1) >= 10 ? ""+(week-1) : (week-1) <= 0 ?"0":"0"+(week-1);
        String dateStr3 = (week-2) >= 10 ? ""+(week-2) : (week-2) <= 0 ?"0":"0"+(week-2);
        String dateStr4 = (week-3) >= 10 ? ""+(week-3) : (week-3) <= 0 ?"0":"0"+(week-3);
        String dateStr5 = (week-4) >= 10 ? ""+(week-4) : (week-4) <= 0 ?"0":"0"+(week-4);
        String dateStr6 = (week-5) >= 10 ? ""+(week-5) : (week-5) <= 0 ?"0":"0"+(week-5);
        String dateStr7 = (week-6) >= 10 ? ""+(week-6) : (week-6) <= 0 ?"0":"0"+(week-6);
        String dateStr8 = (week-7) >= 10 ? ""+(week-7) : (week-7) <= 0 ?"0":"0"+(week-7);
        String dateStr9 = (week-8) >= 10 ? ""+(week-8) : (week-8) <= 0 ?"0":"0"+(week-8);
        String dateStr10 = (week-9) >= 10 ? ""+(week-9) : (week-9) <= 0 ?"0":"0"+(week-9);
        String dateStr11 = (week-10) >= 10 ? ""+(week-10) : (week-10) <= 0 ?"0":"0"+(week-10);
        String dateStr12 = (week-11) >= 10 ? ""+(week-11) : (week-11) <= 0 ?"0":"0"+(week-11);
        paramDateRecentWeekBuilder.append("and to_char(t.bus_date, 'yyyy') = '"+nowYear+"' and to_char(t.bus_date, 'WW') in ('"+dateStr1+"','"+dateStr2+"','"+dateStr3+"','"+dateStr4+"','"+dateStr5+"','"+dateStr6+"','"+dateStr7+"','"+dateStr8+"','"+dateStr9+"','"+dateStr10+"','"+dateStr11+"','"+dateStr12+"')");
        recentWeekArr = new String[]{dateStr12,dateStr11,dateStr10,dateStr9,dateStr8,dateStr7,dateStr6,dateStr5,dateStr4,dateStr3,dateStr2,dateStr1};
        //上一年
        LocalDate parseLastDate = parseDate.minusYears(1);
        String lastYear = String.valueOf(parseLastDate.getYear());
        int weekLast= parseLastDate.get(weekFields.weekOfWeekBasedYear());
        String dateLastStr1 = weekLast >= 10 ? ""+weekLast : "0"+weekLast;
        String dateLastStr2 = (weekLast-1) >= 10 ? ""+(weekLast-1) : (weekLast-1) <= 0 ?"0":"0"+(weekLast-1);
        String dateLastStr3 = (weekLast-2) >= 10 ? ""+(weekLast-2) : (weekLast-2) <= 0 ?"0":"0"+(weekLast-2);
        String dateLastStr4 = (weekLast-3) >= 10 ? ""+(weekLast-3) : (weekLast-3) <= 0 ?"0":"0"+(weekLast-3);
        String dateLastStr5 = (weekLast-4) >= 10 ? ""+(weekLast-4) : (weekLast-4) <= 0 ?"0":"0"+(weekLast-4);
        String dateLastStr6 = (weekLast-5) >= 10 ? ""+(weekLast-5) : (weekLast-5) <= 0 ?"0":"0"+(weekLast-5);
        String dateLastStr7 = (weekLast-6) >= 10 ? ""+(weekLast-6) : (weekLast-6) <= 0 ?"0":"0"+(weekLast-6);
        String dateLastStr8 = (weekLast-7) >= 10 ? ""+(weekLast-7) : (weekLast-7) <= 0 ?"0":"0"+(weekLast-7);
        String dateLastStr9 = (weekLast-8) >= 10 ? ""+(weekLast-8) : (weekLast-8) <= 0 ?"0":"0"+(weekLast-8);
        String dateLastStr10 = (weekLast-9) >= 10 ? ""+(weekLast-9) : (weekLast-9) <= 0 ?"0":"0"+(weekLast-9);
        String dateLastStr11 = (weekLast-10) >= 10 ? ""+(weekLast-10) : (weekLast-10) <= 0 ?"0":"0"+(weekLast-10);
        String dateLastStr12 = (weekLast-11) >= 10 ? ""+(weekLast-11) : (weekLast-11) <= 0 ?"0":"0"+(weekLast-11);
        paramDateRecentWeekCompareBuilder.append("and to_char(t.bus_date, 'yyyy') = '"+lastYear+"' and to_char(t.bus_date, 'WW') in ('"+dateLastStr1+"','"+dateLastStr2+"','"+dateLastStr3+"','"+dateLastStr4+"','"+dateLastStr5+"','"+dateLastStr6+"','"+dateLastStr7+"','"+dateLastStr8+"','"+dateLastStr9+"','"+dateLastStr10+"','"+dateLastStr11+"','"+dateLastStr12+"')");
        recentWeekCompareArr = new String[]{dateLastStr12,dateLastStr11,dateLastStr10,dateLastStr9,dateLastStr8,dateLastStr7,dateLastStr6,dateLastStr5,dateLastStr4,dateLastStr3,dateLastStr2,dateLastStr1};
    }
    /**
     * 获得传入时间的最近7天
     */
    private void getDayCompare(String dateStr) {
        DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate parseDate = LocalDate.parse(dateStr, fmDate);
        //当前时间往前推七天
        String dateStr1 = parseDate.minus(1, ChronoUnit.DAYS).format(fmDate);
        String dateStr2 = parseDate.minus(2, ChronoUnit.DAYS).format(fmDate);
        String dateStr3 = parseDate.minus(3, ChronoUnit.DAYS).format(fmDate);
        String dateStr4 = parseDate.minus(4, ChronoUnit.DAYS).format(fmDate);
        String dateStr5 = parseDate.minus(5, ChronoUnit.DAYS).format(fmDate);
        String dateStr6 = parseDate.minus(6, ChronoUnit.DAYS).format(fmDate);
        paramDateRecentDayBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd') in ('"+dateStr+"','"+dateStr1+"','"+dateStr2+"','"+dateStr3+"','"+dateStr4+"','"+dateStr5+"','"+dateStr6+"')");
        recentDayArr = new String[]{dateStr6,dateStr5,dateStr4,dateStr3,dateStr2,dateStr1,dateStr};
        //上一年
        LocalDate parseLastDate = parseDate.minusYears(1);
        String dateLastStr = parseLastDate.format(fmDate);
        String dateLastStr1 = parseLastDate.minus(1, ChronoUnit.DAYS).format(fmDate);
        String dateLastStr2 = parseLastDate.minus(2, ChronoUnit.DAYS).format(fmDate);
        String dateLastStr3 = parseLastDate.minus(3, ChronoUnit.DAYS).format(fmDate);
        String dateLastStr4 = parseLastDate.minus(4, ChronoUnit.DAYS).format(fmDate);
        String dateLastStr5 = parseLastDate.minus(5, ChronoUnit.DAYS).format(fmDate);
        String dateLastStr6 = parseLastDate.minus(6, ChronoUnit.DAYS).format(fmDate);
        paramDateRecentDayCompareBuilder.append("and to_char(t.bus_date, 'yyyy-MM-dd') in ('"+dateLastStr+"','"+dateLastStr1+"','"+dateLastStr2+"','"+dateLastStr3+"','"+dateLastStr4+"','"+dateLastStr5+"','"+dateLastStr6+"')");
        recentDayCompareArr = new String[]{dateLastStr6,dateLastStr5,dateLastStr4,dateLastStr3,dateLastStr2,dateLastStr1,dateLastStr};
    }

    /**
     * 1、按日<近7日>、
     * 2、周<近12周>、
     * 3、月<近12个月>、
     * 4、年<近5年
     */
    public void setLineType(Integer lineType) {
        this.lineType = lineType;
        if (1 == lineType) {
            this.dateFormat="yyyy-MM-dd";
        }else if(2 == lineType){
            this.dateFormat="WW";
        }else if(3 == lineType){
            this.dateFormat="yyyy-MM";
        }else if(4 == lineType){
            this.dateFormat="yyyy";
        }
    }
    public String getConditionAreaStr() { return paramAreaBuilder.toString(); }

    public String getConditionUnitStr() {
        return paramUnitBuilder.toString();
    }

    public String getConditionDateStr() {
        return paramDateBuilder.toString();
    }

    public String getConditionCompareDateStr() {
        return paramDateCompareBuilder.toString();
    }

    public String getConditionRecentYearDateStr() { return paramDateRecentYearBuilder.toString(); }

    public String getConditionRecentYearCompareDateStr() { return paramDateRecentYearCompareBuilder.toString(); }

    public String getConditionRecentDayDateStr() { return paramDateRecentDayBuilder.toString(); }

    public String getConditionRecentDayCompareDateStr() { return paramDateRecentDayCompareBuilder.toString(); }

    public String getConditionRecentWeekDateStr() { return paramDateRecentWeekBuilder.toString(); }

    public String getConditionRecentWeekCompareDateStr() { return paramDateRecentWeekCompareBuilder.toString(); }

    public String getConditionRecentMonthDateStr() { return paramDateRecentMonthBuilder.toString(); }

    public String getConditionRecentMonthCompareDateStr() { return paramDateRecentMonthCompareBuilder.toString(); }

    //***********************************************************以下属性为编译器生成 没做修改*****************************************************

    public String getStartDate() { return startDate; }

    public String getEndDate() { return endDate; }

    public String getSgbCode() {
        return sgbCode;
    }

    public String getSgbName() {
        return sgbName;
    }

    public String getSpareCode() {
        return spareCode;
    }

    public String getSpareCode1() {
        return spareCode1;
    }

    public String getUnitLevel() {
        return unitLevel;
    }

    public String getUnitCode() {
        return unitCode;
    }

    public String getTargetType() {
        return targetType;
    }

    public String getTargetType2() {
        return targetType2;
    }

    public void setTargetType(String targetType) { this.targetType = targetType; }

    public void setTargetType2(String targetType2) { this.targetType2 = targetType2; }

    public Integer getDateType() {
        return dateType;
    }

    public String[] getTargetTypeArr() { return targetTypeArr; }

    public void setTargetTypeArr(String[] targetTypeArr) { this.targetTypeArr = targetTypeArr; }

    public String[] getRecentYearArr() { return recentYearArr; }

    public void setRecentYearArr(String[] recentYearArr) { this.recentYearArr = recentYearArr; }

    public String[] getRecentYearCompareArr() { return recentYearCompareArr; }

    public void setRecentYearCompareArr(String[] recentYearCompareArr) { this.recentYearCompareArr = recentYearCompareArr; }

    public String[] getRecentDayArr() { return recentDayArr; }

    public void setRecentDayArr(String[] recentDayArr) { this.recentDayArr = recentDayArr; }

    public String[] getRecentDayCompareArr() { return recentDayCompareArr; }

    public void setRecentDayCompareArr(String[] recentDayCompareArr) { this.recentDayCompareArr = recentDayCompareArr; }

    public String[] getRecentWeekArr() { return recentWeekArr; }

    public void setRecentWeekArr(String[] recentWeekArr) { this.recentWeekArr = recentWeekArr; }

    public String[] getRecentWeekCompareArr() { return recentWeekCompareArr; }

    public void setRecentWeekCompareArr(String[] recentWeekCompareArr) { this.recentWeekCompareArr = recentWeekCompareArr; }

    public String[] getRecentMonthArr() { return recentMonthArr; }

    public void setRecentMonthArr(String[] recentMonthArr) { this.recentMonthArr = recentMonthArr; }

    public String[] getRecentMonthCompareArr() { return recentMonthCompareArr; }

    public void setRecentMonthCompareArr(String[] recentMonthCompareArr) { this.recentMonthCompareArr = recentMonthCompareArr; }

    public boolean isCompare() { return compare; }

    public void setCompare(boolean compare) { this.compare = compare; }

    public Integer getSubstrIndex() {
        return substrIndex;
    }

    public void setSubstrIndex(Integer substrIndex) { this.substrIndex = substrIndex; }

    public Integer getLineType() { return lineType; }

    public String getDateFormat() { return dateFormat; }

    public void setDateFormat(String dateFormat) { this.dateFormat = dateFormat; }

    public String getConditionRecentDateStr() { return conditionRecentDateStr; }

    public void setConditionRecentDateStr(String conditionRecentDateStr) { this.conditionRecentDateStr = conditionRecentDateStr; }

    public String getConditionRecentCompareDateStr() { return conditionRecentCompareDateStr; }

    public void setConditionRecentCompareDateStr(String conditionRecentCompareDateStr) { this.conditionRecentCompareDateStr = conditionRecentCompareDateStr; }

    public String getTablename() { return tablename; }

    public void setTablename(String tablename) { this.tablename = tablename; }

}
